<?php

require( realpath('..') . '/includes/admin.php' );

auth();
$dora->database();

if( action('add') ) {
	extract($_POST);
	
	$file_name = $_FILES['picture']['name'];
	$extend = pathinfo( $file_name ); 
	$extend = strtolower($extend["extension"]);
	$new_file_name = rand(1,100000) . "." . $extend;
	$picture_path = 'uploads/' . $new_file_name;
	
	if(@move_uploaded_file($_FILES['picture']['tmp_name'], '../' . $picture_path)) {
		
	}
	else {
		$dora->lib('message');
		$dora->message->set('房源图片上传失败');
		$dora->view('house_fo');
		exit;
	}
	
	$sql = "insert into house(name, picture_path, content) values ('$name', '$picture_path', '$content')";
	$dora->db->query($sql);
	
	$dora->lib('message');
	$dora->message->set('新增房源成功');
	
	$dora->view('house_fo');
	
}
else {
	$dora->view('house_add');
}

?>